package com.ruoyi.statisticalCenter.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.statisticalCenter.domain.ScOutBoundReturnSheetSet;
import com.ruoyi.statisticalCenter.domain.ScOutReturnSheet;
import com.ruoyi.statisticalCenter.domain.vo.ScOutReturnSheetVo;
import com.ruoyi.statisticalCenter.service.ScOutReturnSheetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sc/outReturnSheet")
@Api(tags = "统计中心-出港返利毛利表")
public class ScOutReturnSheetController {
    @Autowired
    private ScOutReturnSheetService scOutReturnSheetService;

    @ApiOperation("汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody ScOutReturnSheetVo vo) {
        if (vo != null) {
            String startTime = vo.getStartTime().replace("-", "");
            String endTime = vo.getEndTime().replace("-", "");
            vo.setStartTime(startTime);
            vo.setEndTime(endTime);
        }
            return scOutReturnSheetService.collect(vo);
    }

    @ApiOperation("显示配置列表")
    @GetMapping("/selectAll")
    public R selectAll() {
        ScOutBoundReturnSheetSet scOutBoundReturnSheetSet = scOutReturnSheetService.select();
        com.alibaba.fastjson.JSONObject jsonObject = new JSONObject();
        jsonObject.put("list", scOutBoundReturnSheetSet);
        jsonObject.put("fields", scOutReturnSheetService.initTable());

        return R.ok(jsonObject);
    }

    @ApiOperation("修改配置列表")
    @PostMapping("/update")
    public R update(ScOutBoundReturnSheetSet sheetSet) {
        Boolean isUpdate = scOutReturnSheetService.update(sheetSet);
        if (isUpdate) {
            return R.ok("修改成功");
        } else {
            return R.fail("修改失败");
        }
    }
}
